package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author youli.chen
 * @version v1.0
 * @description: 呼叫中心类型枚举类
 * @date 2019/2/12 15:32
 * @since v1.0
 */
@Getter
public enum CallCenterTypeEnum {
    /**
     * 呼叫中心类型枚举
     */
    CALL_CENTER_DU_YAN(XbbRefTypeEnum.CALL_CENTER_DU_YAN.getCode(), "enum.callCenterType.name.call_center_du_yan", "callCenterDuYan"),

    CALL_CENTER_XBB(XbbRefTypeEnum.CALL_CENTER_XBB.getCode(), "enum.callCenterType.name.call_center_xbb", "callCenterXbb"),

    CALL_CENTER_ALI_YUN(XbbRefTypeEnum.CALL_CENTER_ALI_YUN.getCode(), "enum.callCenterType.name.call_center_ali_yun", "callCenterAliYun"),

    UNKNOWN(404, "enum.callCenterType.name.unknown", "unknown");
    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    /**
     * 构造一个<code>AppStoreTypeEnum</code>枚举对象
     *
     * @param code  枚举Code
     * @param name  枚举名称
     * @param alias 枚举别名
     */
    CallCenterTypeEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     * @return AppStoreTypeEnum
     */
    public static CallCenterTypeEnum getByAlias(String alias) {
        for (CallCenterTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     * @return AppStoreTypeEnum
     */
    public static CallCenterTypeEnum getByCode(Integer code) {
        for (CallCenterTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<AppStoreTypeEnum>
     */
    public List<CallCenterTypeEnum> getAllEnum() {
        List<CallCenterTypeEnum> list = new ArrayList<>();
        for (CallCenterTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (CallCenterTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
